<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all" />

</head>
<body>
<input type="hidden" name="flag" th:value="${sWarehouse!=null?sWarehouse.warehouseId:'' }"/>
	<div class="layui-container" style="margin-top: 20px">
		<form class="layui-form" lay-filter="warehouseForm" id="empData">
		<input type="hidden" name="createTime" th:value="${sWarehouse!=null?sWarehouse.createTime:'' }">
			<div class="layui-form-item"
				 style="padding-top: 15px; margin-right: 45px;">
				<label class="layui-form-label">仓库编号：</label>
				<div class="layui-input-block">
					<input type="text" name="warehouseId" th:value="${sWarehouse!=null?sWarehouse.warehouseId:'' }" th:readonly="${sWarehouse!= ''}? 'readonly':'false'"
						   lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
		
			<div class="layui-form-item"
				style="padding-top: 15px; margin-right: 45px;">
				<label class="layui-form-label">仓库名称：</label>
				<div class="layui-input-block">
					<input type="text" name="warehouseName" th:value="${sWarehouse!=null?sWarehouse.warehouseName:''}"
						lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" style="margin-right: 45px;">
				<label class="layui-form-label">电话：</label>
				<div class="layui-input-block">
					<input type="text" name="contactPhone" th:value="${sWarehouse!=null?sWarehouse.contactPhone:''}" lay-verify="required"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" style="margin-right: 45px;">
				<label class="layui-form-label">负责人：</label>
				<div class="layui-input-block">
					<input type="text" name="principal" th:value="${sWarehouse!=null?sWarehouse.principal:''}"
						lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item"
				style="padding-top: 15px; margin-right: 45px;">
				<label class="layui-form-label">面积：</label>
				<div class="layui-input-block">
					<input type="text" name="area" autocomplete="off" th:value="${sWarehouse!=null?sWarehouse.area:''}"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
			<label class="layui-form-label">网点名称</label>
			<div class="layui-input-block">
				<select name="nodeNetworkId" lay-verify="required"  >
					<option>请选择</option>
					<option th:each="network:${networkList}" th:value="${network.networkId}" th:text="${network.networkName}" th:selected="${sWarehouse!=null?sWarehouse.nodeNetworkId:'' == network.networkId }"></option>

				</select>
			</div>
		</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" id="submit" lay-submit
						lay-filter="warehouseForm">
						<i class="layui-icon">提交</i>
					</button>
					<button type="reset" class="layui-btn layui-btn-primary">
						<i class="layui-icon">重置</i>
					</button>
				</div>
			</div>
		</form>
	</div>
</body>
<script type="text/javascript" th:src="@{/lib/layui/layui.js}"></script>
<script th:inline="javascript" type="text/javascript">
	//Demo
	layui.use([ 'form', 'layer', 'jquery' ], function() {
		form = layui.form;
		form.render('select', 'test1');
		$ = layui.jquery;
		var edit = $("[name='flag']").val();
		if (edit == "" || edit == null || edit == undefined) {
			 $("[name='warehouseId']").removeAttr("readonly");
		}

		//监听提交
		form.on('submit(warehouseForm)', function(data) {
			var sWarehouse = data.field;
			console.log(JSON.stringify(sWarehouse))
			var index = top.layer.msg('数据提交中，请稍候', {
				icon : 16,
				time : false,
				shade : 0.8
			});
			var method = "";
			if (edit == "" || edit == null || edit == undefined) {
				method = "add";
			} else {
				method = "update";
			}
			
			$.post("/api/warehouse/"+method,sWarehouse,function(d){
				if (d.code == 200) {
					top.layer.close(index);
		            top.layer.msg("员工添加成功！");
		            layer.closeAll("iframe");
		            //刷新父页面
		            parent.location.reload();
				} else {
					layer.msg(d.msg,{"icon":2});
				}
			});
			

			return false;
		});

	});
</script>


</html>